#include <QAction>

#include "actionmanager.h"
#include "uidmanager.h"

ActionManager::ActionManager(QObject *parent) :
    QObject(parent)
{
}

void ActionManager::addAction(QAction *a, const QList<int> &context)
{
    Command cmd;

    cmd.action = a;
    cmd.context = context;
    m_commands.append(cmd);
}

void ActionManager::removeAction(QAction *a)
{
    for(int i =0; i < m_commands.count(); i++) {
        if (m_commands.at(i).action == a) {
            m_commands.removeAt(i);
            break;
        }
    }
}


void ActionManager::contextChanged(const QList<int> &context)
{
    foreach (const Command &cmd, m_commands) {
        bool enable = false;

        foreach (int uid, context) {
            if (cmd.context.contains(uid)) {
                enable = true;
                break;
            }
        }
        cmd.action->setEnabled(enable);
    }
}
